package net.melon.sso.inst.ssh.web;

import javax.annotation.Resource;

import net.esj.basic.exception.MelonException;
import net.esj.basic.view.AbstractPluginPageAction;
import net.melon.sso.pojo.Config;
import net.melon.sso.service.SSOManage;
import net.melon.sso.service.SSOService;

public class ConfigAction extends AbstractPluginPageAction<Config, Config> {

	/**
	 * 
	 */
	private static final long serialVersionUID = 3266453383483175904L;
	
	@Resource
	private SSOService ssoService;
	
	@Resource
	private SSOManage ssoManage;
	
	@Override
	protected void doAdd() throws Exception {
		if(ssoService.checkConfigUnique(entity,true)){
			super.doAdd();
		}else{
			throw new MelonException("存在冲突的编号或者关键字 ");
		}
	}
	
	@Override
	protected void afterAdd() {
		ssoService.loadConfig(true);
	}
	
	@Override
	protected void doLoad() {
		entity = ssoService.getConfig(id);
	}

	@Override
	protected void doUpdate() throws Exception {
		if(ssoService.checkConfigUnique(entity,false)){
			super.doUpdate();
		}else{
			throw new MelonException("存在冲突的编号或者关键字 ");
		}
		
	}
	@Override
	protected void afterUpdate() {
		ssoService.loadConfig(true);
	}
	
	@Override
	protected void doDelete() throws Exception {
		entity = ssoService.getConfig(deletes);
		if(ssoManage.checkDeleteConfig(entity)){
			super.doDelete();
		}else{
			throw new MelonException("关键字  "+entity.getKey()+" ,已经使用不能删除");
		}
	}
	@Override
	protected void afterDelete() {
		ssoService.loadConfig(true);
	}

	public void setEntity(Config entity){
		this.entity = entity;
	}
	
	public Config getEntity(){
		return entity;
	}
	
}
